<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>The source code</title>
  <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
  <style type="text/css">
    .highlight { display: block; background-color: #ddd; }
  </style>
  <script type="text/javascript">
    function highlight() {
      document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
    }
  </script>
</head>
<body onload="prettyPrint(); highlight();">
  <pre class="prettyprint lang-js">var textUtil = require(&quot;../utils/text_util&quot;);

var BoundingRect = require(&quot;./BoundingRect&quot;);

var _constants = require(&quot;../utils/constants&quot;);

var WILL_BE_RESTORED = _constants.WILL_BE_RESTORED;

<span id='qrenderer-graphic-RectText'>/**
</span> * @class qrenderer.graphic.RectText 
 * @docauthor 大漠穷秋 &lt;damoqiongqiu@126.com&gt;
 */
var tmpRect = new BoundingRect();

var RectText = function RectText() {};
<span id='qrenderer-graphic-RectText-method-constructor'>/**
</span> * @method constructor RectText
 */


RectText.prototype = {
  constructor: RectText,

<span id='qrenderer-graphic-RectText-method-drawRectText'>  /**
</span>   * Draw text in a rect with specified position.
   * @param  {CanvasRenderingContext2D} ctx
   * @param  {Object} rect Displayable rect
   */
  drawRectText: function drawRectText(ctx, rect) {
    var style = this.style;
    rect = style.textRect || rect; // Optimize, avoid normalize every time.

    this.__dirty &amp;&amp; textUtil.normalizeTextStyle(style, true);
    var text = style.text; // Convert to string

    text != null &amp;&amp; (text += &#39;&#39;);

    if (!textUtil.needDrawText(text, style)) {
      return;
    } // FIXME
    // Do not provide prevEl to `textUtil.renderText` for ctx prop cache,
    // but use `ctx.save()` and `ctx.restore()`. Because the cache for rect
    // text propably break the cache for its host elements.


    ctx.save(); // Transform rect to view space

    var transform = this.transform;

    if (!style.transformText) {
      if (transform) {
        tmpRect.copy(rect);
        tmpRect.applyTransform(transform);
        rect = tmpRect;
      }
    } else {
      this.applyTransform(ctx);
    } // transformText and textRotation can not be used at the same time.


    textUtil.renderText(this, ctx, text, style, rect, WILL_BE_RESTORED);
    ctx.restore();
  }
};
var _default = RectText;
module.exports = _default;</pre>
</body>
</html>
